package cl.lexer.validator;

import cl.lexer.Token;
import cl.lexer.TokenType;

public class StringValidator implements TokenValidator {

    @Override
    public TokenType getType() {
        return TokenType.STRING;
    }

    @Override
    public boolean isValid(String value) {
        if(value.length() < 2 || !value.startsWith("\"") || !value.endsWith("\"") || 
                value.substring(1, value.length() - 1).indexOf("\"") != -1) {
            return false;
        }
    
        return true;
    }

    @Override
    public boolean possiblyValid(String value) {
        if(value.isEmpty()) {
            return true;
        } else if(value.length() > 2 && value.substring(1, value.length() - 1).indexOf("\"") != -1) {
            return false;
        } else if(!value.startsWith("\"")) {
            return false;
        }
    
        return true;
    }

    @Override
    public Token generateToken(String value) {
        return new Token(TokenType.STRING, value);
    }

}
